package com.qianfeng.openapi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.openapi.mapper.ApiMappingMapper;
import com.qianfeng.openapi.pojo.ApiMapping;
import com.qianfeng.openapi.service.ApiMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class ApiMappingServiceImpl implements ApiMappingService {
    @Autowired
    private ApiMappingMapper apiMappingMapper;
    @Override
    public void insertApiMapping(ApiMapping apiMapping) {
        apiMappingMapper.insertApiMapping(apiMapping);
    }

    @Override
    public void deleteApiMapping(int[] ids) {
        apiMappingMapper.deleteApiMapping(ids);
    }

    @Override
    public void updateApiMapping(ApiMapping apiMapping) {
        apiMappingMapper.updateApiMapping(apiMapping);
    }

    @Override
    public ApiMapping selectApiMappingByGatewayApiName(String gatewayApiName) {
        ApiMapping apiMapping = apiMappingMapper.selectApiMappingByGatewayApiName(gatewayApiName);
        return apiMapping;
    }

    @Override
    public PageInfo<ApiMapping> getAllApiMapping(int page, int limit, ApiMapping apiMapping) {
        PageHelper.startPage(page, limit);
        List<ApiMapping> allApiMapping = apiMappingMapper.getAllApiMapping(apiMapping);
        PageInfo<ApiMapping> pageInfo = new PageInfo<>(allApiMapping);
        return pageInfo;
    }
}
